package com.buptlogistics.creditinvestigation.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.buptlogistics.creditinvestigation.R;
import com.buptlogistics.creditinvestigation.app.BaseFragment;
import com.buptlogistics.creditinvestigation.app.BaseFragmentActivity;
import com.buptlogistics.creditinvestigation.fragment.*;


/**
 * 包名：com.ccmzchuang.zixiba.activity
 * 类描述：
 * 创建人：Administrator
 * 邮箱：fuxuemingzhu@163.com
 * 创建时间：2015/9/5 22:17
 * <p/>
 * 修改人：Administrator
 * 修改时间：2015/9/5 22:17
 * 修改备注：
 *
 * @version 1.0
 */
public class CommonActivity extends BaseFragmentActivity {

    private ImageView iv_back;
    private TextView tv_title;
    private LinearLayout ll_common;
    private BaseFragment fragment;

    private String title;
    private int fragmentType;

    private FragmentManager fragmentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_common);

        fragmentManager = getSupportFragmentManager();


        // 获取启动该Result的Intent
        Intent intent = getIntent();
        // 获取该intent所携带的数据
        Bundle data = intent.getExtras();
        // 从Bundle包中取出数据
        fragmentType = data.getInt("fragmentType");
        switch (fragmentType) {
            case 0:
                title = "空白界面";
                fragment = new BaseFragment();
                break;
            case 1:
                title = "贷款";
                fragment = new LoanFragment();
                break;
            case 2:
                title = "贷款申请";
                fragment = new DeserveFragment();
                break;
            case 3:
                title = "贷款申请";
                fragment = new DeserveDetailFragment();
                break;
            case 4:
                title = "贷款申请";
                fragment = new DeserveCheckFragment();
                break;
            case 5:
                title = "贷款审批";
                fragment = new DeserveApplyFragment();
                break;
            case 6:
                title = "付款承诺";
                fragment = new ContractPayFragment();
                break;
            case 7:
                title = "等待审核";
                fragment = new DeservePledgeFragment();
                break;
            case 8:
                title = "仓储协议";
                fragment = new LoanConfirmAgreementHousingFragment();
                break;
            case 9:
                title = "应收账款融资详情";
                fragment = new DeserveSuccessDetailFragment();
                break;
            case 10:
                title = "货物到期提醒";
                fragment = new AlertFragment();
                break;
            case 11:
                title = "订单通知";
                fragment = new DeliveryAlertFragment();
                break;
            case 12:
                title = "发货通知成功";
                fragment = new DeliverySuccessFragment();
                break;

        }


        initViews();
        initEvents();

        addFragment(fragment);
    }

    @Override
    protected void initViews() {
        iv_back = (ImageView) findViewById(R.id.iv_common_back);
        tv_title = (TextView) findViewById(R.id.tv_common_titile);
        ll_common = (LinearLayout) findViewById(R.id.ll_common);

    }

    @Override
    protected void initEvents() {
        tv_title.setText(title);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    private void addFragment(BaseFragment fragment) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        //是rl 不是ll
        //好可恶啊，整了好久  就是因为这个搞错了
        fragmentTransaction.replace(R.id.rl_common, fragment);
        fragmentTransaction.commit();
    }

}
